﻿# coding: utf-8

import wx
import wx.lib.filebrowsebutton as filebrowse
import wx.lib.agw.labelbook as LB

from GlobalSetting.wxPanelGSGeneral import wxPanelGSGeneral

class CNoteBookGlobalSetting(wx.Treebook):
    def __init__(self, parent):
        wx.Treebook.__init__(self, parent, -1, style = wx.NB_LEFT)
        
        self.AddPage(wxPanelGSGeneral(self), TD.GS_GENERAL)
        self.AddPage(wx.Panel(self), TD.GS_HISTORY)
        self.AddPage(wx.Panel(self), TD.GS_LANGUAGE)
        
class wxDialogGlobalSetting(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, -1, title = TD.DIALOG_GLOBAL_SETTING, size = (640, 480), style = wx.CAPTION)
        
        self.Center()
        
        # Create note book.
        self.Center()
        self._book = CNoteBookGlobalSetting(self)
            
        # Layout
        ok = wx.Button(self, wx.ID_OK, TD.BUTTON_OK)
        cancel = wx.Button(self, wx.ID_CANCEL, TD.BUTTON_CANCEL)
        apply = wx.Button(self, wx.ID_APPLY, TD.BUTTON_APPLY)
        
        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer1.AddStretchSpacer()
        sizer1.Add(ok, 0, wx.EXPAND|wx.ALL, border = 5)
        sizer1.Add(cancel, 0, wx.EXPAND|wx.ALL, border = 5)
        sizer1.Add(apply, 0, wx.EXPAND|wx.ALL, border = 5)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self._book, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border = 10)
        sizer.Add(sizer1, 0, wx.EXPAND|wx.TOP, border = 10)
        
        self.SetSizer(sizer)
        
        # Bind events
        self.Bind(wx.EVT_BUTTON, self.__OnCmdOk, ok)
        self.Bind(wx.EVT_BUTTON, self.__OnCmdCancel, cancel)
        self.Bind(wx.EVT_BUTTON, self.__OnCmdApply, apply)
        
    def __OnCmdOk(self, e):
        GLOBAL_SETTING.Save()
        GLOBAL_SETTING.Apply()
        e.Skip()
        
    def __OnCmdCancel(self, e):
        GLOBAL_SETTING.Load()
        self.Close()
        e.Skip()
        
    def __OnCmdApply(self, e):
        GLOBAL_SETTING.Save()
        GLOBAL_SETTING.Apply()
        
        
        